﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Infrerture.Interfaces;

namespace Traceability.Infrerture.Inerfrment
{
    public class Repository<T>:IBaseRepository<T> where T : class
    {
        private readonly MyDbContext db;

        public Repository(MyDbContext db)
        {
            this.db = db;
        }

        public async Task<int> Add(T t)
        {
            db.Set<T>().Add(t);
            return await db.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public async Task<T> GetValue(int id)
        {
            return await db.Set<T>().FindAsync(id);
        }

        public async Task<int> Update(T t)
        {
           db.Set<T>().Update(t);
            return await db.SaveChangesAsync();
        }



    }
}
